
*************
***Table 1*** 
*************

*Years since independence

clear all

import delimited "Datasets/iisystem.dat"
rename v1 gwno
rename v2 gwabb
rename v3 countryname
rename v4 sysmembfrom
rename v5 sysmembto

label variable gwno "Gleditsch & Ward country code"
label variable gwabb "Gleditsch & Ward country abbreviation"
label variable countryname "Gleditsch & Ward country name"
notes gwno: Source: Kristian S. Gleditsch & Michael D. Ward, 1999. A Revised List of Independent States since the Congress of Vienna. International Interactions 1999
notes gwabb: Source: Kristian S. Gleditsch & Michael D. Ward, 1999. A Revised List of Independent States since the Congress of Vienna. International Interactions 1999
notes countryname: Source: Kristian S. Gleditsch & Michael D. Ward, 1999. A Revised List of Independent States since the Congress of Vienna. International Interactions 1999

/* Including the Occupied Palestinian Territories from 1967 */

set obs `=_N+1'
replace countryname="Occupied Palestinian Territories" in l 
replace gwno=667 if countryname=="Occupied Palestinian Territories" 
notes gwno: The Occupied Palestinian Territories have been added to the original list as gwno= 667
replace gwabb="OPT" if countryname=="Occupied Palestinian Territories"
replace sysmembfrom="11:06:1967" if countryname=="Occupied Palestinian Territories"
replace sysmembto="31:12:2012" if countryname=="Occupied Palestinian Territories"

/* Creating stata date and numeric year variables */

capture drop smfromdate 
capture drop smtodate
capture drop smfromyear
capture drop smtoyear

gen smfromdate = .
gen smtodate = .
replace smfromdate = date(sysmembfrom,"DMY",2100)
replace smtodate = date(sysmembto,"DMY",2100)
format smfromdate %tdDDmonCCYY
format smtodate %tdDDmonCCYY
label variable smfromdate "GW system member from date"
label variable smtodate "GW system member to date"


gen smfromyear = .
gen smtoyear = .
replace smfromyear = year(smfromdate)
replace smtoyear = year(smtodate)
label variable smfromyear "GW system member from year"
label variable smtoyear "GW system member to year"

/* Adjustments to the Gleditsch & Ward country system dates */
/* Adjustments for states  existing in 1816 */
replace smfromyear = 1815 if smfromyear == 1816 

/* Independence dates */
capture drop indepyear
gen indepyear = .
replace indepyear = smfromyear if smfromyear != 1816
label variable indepyear "Year of independence, GW system"



/* Independence dates for coutnries with multiple entries */
/* Pre-1815 dates are from Strand et al. Why Waves (footnote 19) */
replace indepyear = 1804 if gwno == 41 
replace indepyear = 1878 if gwno == 340
replace indepyear = 1868 if gwno == 341
replace indepyear = 1918 if gwno == 366
replace indepyear = 1918 if gwno == 367
replace indepyear = 1918 if gwno == 368
replace indepyear = 1815 if gwno == 580 
replace indepyear = 1700 if gwno == 600 
replace indepyear = 1700 if gwno == 615 
replace indepyear = 1705 if gwno == 616 
replace indepyear = 1711 if gwno == 620 
replace indepyear = 1827 if gwno == 651
replace indepyear = 1747 if gwno == 700 
replace indepyear = 1700 if gwno == 775 

/* The remaining pre-1815 countries: */
replace indepyear = 1700 if gwno == 200
replace indepyear = 1700 if gwno == 210
replace indepyear = 1700 if gwno == 220
replace indepyear = 1700 if gwno == 225
replace indepyear = 1700 if gwno == 230
replace indepyear = 1700 if gwno == 235
replace indepyear = 1700 if gwno == 300
replace indepyear = 1700 if gwno == 365
replace indepyear = 1700 if gwno == 380
replace indepyear = 1700 if gwno == 390
replace indepyear = 1700 if gwno == 698
replace indepyear = 1700 if gwno == 630
replace indepyear = 1700 if gwno == 640
replace indepyear = 1700 if gwno == 800
replace indepyear = 1700 if gwno == 710
replace indepyear = 1781 if gwno == 2
replace indepyear = 1811 if gwno == 150
replace indepyear = 1701 if gwno == 255
replace indepyear = 1720 if gwno == 325
replace indepyear = 1814 if gwno == 385
replace indepyear = 1768 if gwno == 790

*Independence

gen dur= smtoyear- smfromyear
sort gwno
by gwno: egen dur_sum=sum(dur)
by gwno: gen n=_n
*keep if n==1
drop if smtoyear < 1946
*by religion: egen rel_sum=sum(dur_sum)

*Independence since 1946
capture drop indep1 dur_indep1 dur_indep1_sum indep1byrel
gen indep1 = . 
sort gwno
replace smtoyear = 2014 if smtoyear == 2012
by gwno: replace indep1 = smfromyear if indep1 == .
by gwno: replace indep1 = 1946 if smfromyear < 1946

merge 1:1 gwno using "Datasets/PEWreligion_gwno.dta"

drop if _merge == 2
replace religion = 2 if countryname == "Yemen (Arab Republic of Yemen)"
replace religion = 6 if countryname == "Vietnam, Democratic Republic of"
replace religion = 1 if countryname == "German Democratic Republic"
replace religion = 1 if countryname == "Czechoslovakia"
replace religion = 1 if countryname == "Serbia"
replace religion = 2 if countryname == "Occupied Palestinian Territories"

capture drop if religion == .

gen dur_indep1 = smtoyear - indep1
sort gwno
by gwno: egen dur_indep1_sum=sum(dur_indep1)
sort religion
by religion: egen indep1byrel=sum(dur_indep1_sum)

*Years in war

use "Datasets/124920_1ucdp-prio-_2015.dta", clear

drop if type == 1
drop if type == 2
keep if intensitylevel == 2

sort gwnoa year

drop if gwnoa == gwnoa[_n-1] & year==year[_n-1]

gen religion = .
replace religion = 7 if location == "China"
replace religion = 6 if inlist(location, "North Vietnam, South Vietnam", "South Vietnam", "Vietnam","Vietnam (North Vietnam)","South Vietnam, Vietnam (North Vietnam)")
replace religion = 5 if location == "Israel"
replace religion = 4 if inlist(location, "India","Nepal","Hyderabadh")
replace religion = 3 if inlist(location, "Laos","Thailand","Sri Lanka","Cambodia (Kampuchea)","Myanmar (Burma)")
replace religion = 2 if inlist(location, "Pakistan","Guinea-Bissau","Afghanistan","Tajikistan","Saudi Arabia","Sierra Leone","Indonesia","Syria","Uzbekistan")
replace religion = 2 if inlist(location, "Yemen", "South Yemen","Yemen (North Yemen)","Senegal","Lebanon","Iraq","Iran")
replace religion = 2 if inlist(location, "Bangladesh","Tunisia","Brunei","Guinea","Somalia","Gambia","Djibouti")
replace religion = 2 if inlist(location, "Azerbaijan","Burkina Faso","Morocco","Egypt","Malaysia","Comoros","Mauritania","Niger")
replace religion = 2 if inlist(location, "Mali", "Algeria", "Sudan", "Libya", "Turkey","Chad","Oman","Bosnia-Herzegovina")

replace religion = 1 if religion == .

gen conflict = .
replace conflict = 1 if type > 0

sort religion
by religion: egen war_by_rel=sum(conflict)

